package com.day22.java;

import java.lang.reflect.Constructor;

public class Test1 {
    public static void main(String[] args) {
            try{
                Class c = Class.forName("com.day22.java.Student");// 获取Student类的类类对象
                Student stu = (Student)c.newInstance() ;// 这种方式将调用类无参的构造方法。
                stu.setStuName("Tom");
                System.out.println(stu.getStuName());

                Constructor constructor = c.getConstructor(String.class,int.class,String.class);
                Student stu2 = (Student)constructor.newInstance("Jerry",21,"女");
                System.out.println(stu);

            }catch (Exception ex){
                ex.printStackTrace();
            }
    }
}